package com.example.zlw.singpixdemo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

public class LiveActivity extends AppCompatActivity {

    private static final String TAG = "LiveActivity";
    private FinishBroadCast receiver;

    class FinishBroadCast extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            if ("com.erpo.zlw".equals(intent.getAction())) {
                finish();
            }
        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e(TAG, "onCreate: " );
//        setContentView(R.layout.activity_live);

        registerBroadcast();

        Window window = getWindow();
        window.setGravity(Gravity.START | Gravity.TOP);

        WindowManager.LayoutParams params = window.getAttributes();
        params.x = 0;
        params.y = 0;
        params.width = 1;
        params.height = 1;
        window.setAttributes(params);

    }

    public void registerBroadcast(){

        IntentFilter filter = new IntentFilter("com.erpo.zlw");
        receiver = new FinishBroadCast();
        this.registerReceiver(receiver,filter);
    }

    public void unRegisterbroadcast(){
        if (receiver != null) {
            unregisterReceiver(receiver);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e(TAG, "onDestroy: ");
        unRegisterbroadcast();
    }
}
